//
//  UILabel+HKExtension.swift
//  App架构Swift
//
//  Created by 胡锦涛 on 2019/2/19.
//  Copyright © 2019 胡锦涛. All rights reserved.
//

import UIKit

// MARK: - UI控件扩展
extension UILabel {
    
    convenience init(_ frame:CGRect ,font: UIFont = UIFont.systemFont(ofSize: 14), textColor: UIColor = UIColor.black, text: String = "", textAlignment: NSTextAlignment = .left, superView: UIView?) {
        self.init()
        self.frame = frame
        self.font = font
        self.textColor = textColor
        self.text = text
        self.textAlignment = textAlignment
        if superView != nil {
            superView!.addSubview(self)
        }
    }
    
    public func set(attriText:String?,lineSpacing:CGFloat = 2) {
        
        guard let text = attriText  else { return  }
        let paraph = NSMutableParagraphStyle()
        paraph.lineSpacing = lineSpacing
        let attributes = [NSAttributedString.Key.font:font,
                          NSAttributedString.Key.paragraphStyle : paraph] as [NSAttributedString.Key : Any]
        attributedText = NSAttributedString(string: text, attributes: attributes)
    }
}
